package com.mldong.modules.cms.controller;

import com.mldong.auth.Perm;
import com.mldong.base.CommonPage;
import com.mldong.base.CommonResult;
import com.mldong.base.IdParam;
import com.mldong.base.IdsParam;
import com.mldong.modules.cms.dto.PagePageParam;
import com.mldong.modules.cms.dto.PageParam;
import com.mldong.modules.cms.service.PageService;
import com.mldong.modules.cms.vo.PageVO;
import com.mldong.validation.Groups;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
    * 单页面 前端控制器
    * </p>
*
* @author mldong
* @since 2022-10-23
*/
@RestController
@Api(tags = "单页面管理")
@RequiredArgsConstructor
public class PageController {
    private final PageService pageService;
    /**
     * 添加单页面
     * @param param
     * @return
     */
    @PostMapping("/cms/page/save")
    @ApiOperation(value = "添加单页面")
    @Perm
    public CommonResult<?> save(@RequestBody @Validated({Groups.Save.class}) PageParam param) {
        pageService.save(param);
        return CommonResult.ok();
    }
    /**
     * 删除单页面
     * @param param
     * @return
     */
    @PostMapping("/cms/page/remove")
    @ApiOperation(value = "删除单页面")
    @Perm
    public CommonResult<?> remove(@RequestBody IdsParam param) {
        pageService.removeBatchByIds(param.getIds());
        return CommonResult.ok();
    }
    /**
     * 修改单页面
     * @param param
     * @return
     */
    @PostMapping("/cms/page/update")
    @ApiOperation(value = "修改单页面")
    @Perm
    public CommonResult<?> update(@RequestBody @Validated({Groups.Update.class}) PageParam param) {
        pageService.update(param);
        return CommonResult.ok();
    }
    /**
     * 查询单个单页面
     * @param param
     * @return
     */
    @PostMapping("/cms/page/detail")
    @ApiOperation(value = "查询单个单页面")
    @Perm
    public CommonResult<PageVO> detail(@RequestBody IdParam param) {
        PageVO page = pageService.findById(param.getId());
        return CommonResult.data(page);
    }
    /**
     *分页查询单页面列表
     * @param param
     * @return
     */
    @PostMapping("/cms/page/page")
    @ApiOperation(value = "分页查询单页面列表")
    @Perm
    public CommonResult<CommonPage<PageVO>> page(@RequestBody PagePageParam param) {
        return CommonResult.data(pageService.page(param));
    }
}
